package com.yoyo.itravel.service.impl;

import com.yoyo.itravel.bean.TravelerInfo;
import com.yoyo.itravel.dao.ITravelerInfoDao;
import com.yoyo.itravel.exceptions.TravellerInfoException;
import com.yoyo.itravel.service.ITravelerInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;

/**
 * @author liuchaojie
 * @version 1.0
 * @Description 常用旅客服务层接口实现类【服务层】
 * @date 2020/6/18 19:20
 */
@Service
public class TravelerInfoServiceImpl implements ITravelerInfoService {
    @Autowired
    private ITravelerInfoDao travelerInfoDao;

    /**
     * 通过用户id查看常用旅客信息
     * @param userId
     * @return
     * @throws TravellerInfoException
     */
    @Override
    public List<TravelerInfo> showAllTravelerInfo(String userId) throws TravellerInfoException {
        try {
            return travelerInfoDao.showAllTravelerInfo(userId);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new TravellerInfoException("通过用户id查看常用旅客信息失败！...");
        }
    }

    /**
     * 添加常用旅客信息
     * @param travelerInfo
     * @return
     * @throws TravellerInfoException
     */
    @Override
    public int addTraveler(TravelerInfo travelerInfo) throws TravellerInfoException {
        try {
            return travelerInfoDao.addTraveler(travelerInfo);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new TravellerInfoException("添加常用旅客信息失败！...");
        }
    }

    /**
     * 根据常用旅客id修改对应旅客信息
     * @param travelerInfo
     * @return
     * @throws TravellerInfoException
     */
    @Override
    public int updateTraveler(TravelerInfo travelerInfo) throws TravellerInfoException  {
        try {
            return travelerInfoDao.updateTraveler(travelerInfo);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new TravellerInfoException("根据常用旅客id修改对应旅客信息失败！...");
        }
    }

    /**
     * 根据常用旅客id删除对应旅客信息
     * @param travelerId
     * @return
     * @throws TravellerInfoException
     */
    @Override
    public int deleteTraveler(String travelerId) throws TravellerInfoException {
        try {
            return travelerInfoDao.deleteTraveler(travelerId);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new TravellerInfoException("根据常用旅客id删除对应旅客信息失败！...");
        }
    }
}
